package com.storage.mongo;

import java.net.UnknownHostException;

import com.google.code.morphia.Datastore;
import com.google.code.morphia.Morphia;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.Mongo;
import com.mongodb.MongoException;

public class Publish {
	
	Morphia morp;
	Mongo m; 
	DB db; 
	DBCollection topicColl; 
	Datastore ds;
	
	Publish() throws UnknownHostException, MongoException
	{
		morp = new Morphia();
		m = new Mongo( "localhost" , 27017 );
		//drop db
		//m.dropDatabase("mydb");
		db = m.getDB("mydb");
		morp.map(ETopic.class).map(EComments.class);
		ds = morp.createDatastore("mydb");
	}
	
	public String createPublish(String server,String port) throws UnknownHostException, MongoException 
	{
		EPublish publish = new EPublish();
		publish.setServer(server);
		publish.setPort(port);
		ds.save(publish);
		System.out.println("Server details published successfully");
		
		return server+"+"+port;
		
	}
	

}
